Skip to content

[client] fix ios network addresses mac filter#5906

Merged
pappz merged 6 commits intomainfrom
fix/ios-network-addresses-mac-filter
Apr 20, 2026
Merged

[client] fix ios network addresses mac filter#5906
pappz merged 6 commits intomainfrom
fix/ios-network-addresses-mac-filter

Conversation

@pappz
Copy link
Copy Markdown
Collaborator

@pappz pappz commented Apr 16, 2026

Describe your changes

On iOS, networkAddresses() returned an empty list because Apple’s privacy restrictions (since iOS 14) prevent access to real hardware (MAC) addresses. As a result, all interfaces were filtered out by the HardwareAddr == "" check.

Split networkAddresses() into platform-specific implementations:

  • Non-iOS (network_addr.go) retains the original MAC-based filtering logic.
  • iOS (info_ios.go) skips MAC validation entirely.
  • Added additional filtering on iOS to exclude link-local (fe80::/10) and multicast addresses, which are not useful for posture checks.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Refactor

    • Network address discovery has been moved to platform-specific implementations for clearer separation and easier maintenance.
  • New Features

    • iOS now automatically discovers active network interfaces and reports IP prefixes; discovery errors are logged but do not block info retrieval.
    • Non-iOS platforms now collect unique local network addresses, prefer interfaces with hardware identifiers, filter out loopback/link-local/multicast addresses, and de-duplicate results.

pappz added 2 commits April 16, 2026 15:47
iOS does not expose hardware (MAC) addresses due to Apple's privacy
restrictions (since iOS 14), causing networkAddresses() to return an
empty list because all interfaces are filtered out by the HardwareAddr
check. Move networkAddresses() to platform-specific files so iOS can
skip this filter.
Link-local (fe80::) and multicast addresses are not useful for posture
checks and add noise to the reported network addresses. Filter them out
on iOS, consistent with how other parts of the codebase handle these.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 432f87c5-849f-4706-958d-9ca53dbf0522

📥 Commits

Reviewing files that changed from the base of the PR and between e5811dd and 7bcb3f3.

📒 Files selected for processing (2)
  • client/system/info_ios.go
  • client/system/network_addr.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/system/info_ios.go

📝 Walkthrough

Walkthrough

Removed duplicated network-address logic from the generic info file and introduced platform-specific implementations: an iOS networkAddresses() in client/system/info_ios.go and a non-iOS implementation in client/system/network_addr.go. info.go now defers network address population to those platform files.

Changes

Cohort / File(s) Summary
Core cleanup
client/system/info.go
Removed networkAddresses() and isDuplicated() helpers and unused net import; retained context extraction and GetInfoWithChecks flow.
iOS-specific discovery
client/system/info_ios.go
Added iOS networkAddresses() and isDuplicated(): enumerate interfaces, read Addrs(), convert *net.IPNet to NetworkAddress via netip.ParsePrefix, skip loopback/link-local/multicast, de-duplicate by NetIP, log warning only on discovery error, and populate Info.NetworkAddresses.
Non-iOS discovery
client/system/network_addr.go
New //go:build !ios file implementing networkAddresses(), toNetworkAddress(), and isDuplicated(): list interfaces, filter FlagUp and non-empty MAC, call iface.Addrs(), convert *net.IPNet to netip.Prefix, construct NetworkAddress with MAC, skip parse/address errors, and deduplicate by NetIP.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • mlsmaycon

Poem

"I hopped through code with nimble paws,
Split nets, trimmed duplicates, cleaned the laws.
iOS and others find addresses anew,
Each interface pruned, each MAC in view.
🐇✨"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing iOS network addresses filtering to handle MAC address restrictions, which directly addresses the core issue described in the PR.
Description check ✅ Passed The PR description is comprehensive, explaining the iOS MAC address privacy issue, the platform-specific implementation strategy, and the additional filtering logic. Most required template sections are completed, including the bug fix checkbox and documentation decision.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ios-network-addresses-mac-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pappz pappz marked this pull request as ready for review April 16, 2026 14:14
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/system/info_ios.go`:
- Around line 73-74: The multicast filtering currently calls
ipNet.IP.IsLinkLocalMulticast(), which only excludes link-local multicast;
update the check to use ipNet.IP.IsMulticast() instead so all multicast ranges
are filtered out. Locate the loop in client/system/info_ios.go where
ipNet.IP.IsLoopback() / IsLinkLocalUnicast() are checked (the line containing
ipNet.IP.IsLinkLocalMulticast()) and replace that predicate with
ipNet.IP.IsMulticast(), keeping the surrounding continue logic unchanged.

In `@client/system/network_addr.go`:
- Around line 39-41: Replace the unsafe netip.MustParsePrefix call with
netip.ParsePrefix and handle parse errors to avoid panics: where netAddr is
constructed (the code using ipNet.String() to build a NetworkAddress) and the
similar usage in info_ios.go, call netip.ParsePrefix(ipNet.String()), check the
returned error, and if it fails log or ignore that interface entry and continue
(do not panic or add an invalid NetworkAddress); ensure the rest of the logic
that depends on the parsed prefix only runs when parsing succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fffb500e-85a3-4fe9-bcd3-70646c7d915f

📥 Commits

Reviewing files that changed from the base of the PR and between 53b04e5 and 5472c10.

📒 Files selected for processing (3)
  • client/system/info.go
  • client/system/info_ios.go
  • client/system/network_addr.go
💤 Files with no reviewable changes (1)
  • client/system/info.go

Comment thread client/system/info_ios.go Outdated
Comment thread client/system/network_addr.go Outdated
lixmal
lixmal previously approved these changes Apr 16, 2026
…afely

- Replace IsLinkLocalMulticast() with IsMulticast() to filter all multicast ranges, not just link-local
- Replace unsafe MustParsePrefix() with ParsePrefix() and handle errors gracefully by skipping invalid addresses instead of panicking
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/system/info_ios.go`:
- Around line 51-94: Extract the inner per-address loop of networkAddresses into
a helper (e.g., processInterfaceAddress(iface net.Interface, address net.Addr)
(*NetworkAddress, error)); the helper should perform the same checks currently
in the loop: assert address is *net.IPNet, skip loopback/link-local/multicast,
parse prefix via netip.ParsePrefix, build NetworkAddress with Mac set to
iface.HardwareAddr.String(), and return nil on any check/parse failure; keep
duplicate detection by calling isDuplicated(netAddresses, netAddr) from the
caller (or return a sentinel to indicate duplication) so networkAddresses can
remain responsible for appending unique entries and preserve the existing
MAC-check bypass, error handling, and overall behavior.

In `@client/system/network_addr.go`:
- Around line 10-56: The function networkAddresses exceeds Sonar complexity;
extract the inner per-interface/address logic into a small helper (e.g.,
processInterfaceAddresses or collectAddressesFromInterface) that takes an iface
(net.Interface) and the current []NetworkAddress and returns the updated slice
(or new addresses) and/or error; move the addr loop, type assertion to
*net.IPNet, loopback check, prefix parsing (netip.ParsePrefix), creation of
NetworkAddress (NetIP, Mac: iface.HardwareAddr.String()), the non-iOS MAC filter
(iface.HardwareAddr.String() == ""), and the isDuplicated check into that helper
so networkAddresses only iterates interfaces, calls the helper for each up
interface, and appends returned addresses, preserving existing behavior and
error handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ba4b275-a023-4bc8-b983-7d65fdf42015

📥 Commits

Reviewing files that changed from the base of the PR and between 5472c10 and 8cbbd66.

📒 Files selected for processing (2)
  • client/system/info_ios.go
  • client/system/network_addr.go

Comment thread client/system/info_ios.go
Comment thread client/system/network_addr.go
pappz added 3 commits April 20, 2026 10:53
iOS returns a fixed 02:00:00:00:00:00 placeholder for HardwareAddr due to
Apple's privacy restrictions. Setting Mac to "" matches Android's behavior
and avoids sending a meaningless placeholder to the management server.
Lowers cognitive complexity of networkAddresses below the linter threshold
by moving the per-address type-assertion, IP filtering, and prefix parsing
into a small helper.
Lowers cognitive complexity of networkAddresses below the linter threshold
by moving the per-address type-assertion, loopback filter, and prefix
parsing into a small helper, mirroring the iOS implementation.
@sonarqubecloud
Copy link
Copy Markdown

@pappz pappz merged commit 3098f48 into main Apr 20, 2026
42 checks passed
@pappz pappz deleted the fix/ios-network-addresses-mac-filter branch April 20, 2026 09:49
MichaelUray added a commit to MichaelUray/netbird that referenced this pull request Apr 24, 2026
…-addresses

Resolved conflicts against upstream netbirdio#5906 (ios mac filter / network_addr.go
extraction) and netbirdio#5888 (DebugBundle on Android client):

- client/android/client.go: keep both OnUnderlyingNetworkChanged (ours) and
  DebugBundle (upstream), replaced non-ASCII arrow in comment with plain text.
- client/system/info.go: drop duplicated networkAddresses/isDuplicated - they
  now live in client/system/network_addr.go after upstream extraction.
- client/system/network_addr.go: adopt upstream's toNetworkAddress helper
  but keep ctx-aware signature + skipNoMacFilter so Android continues to use
  the external iFace discoverer.
- client/system/info_ios.go: add exported NetworkAddresses(ctx) shim so the
  engine call compiles on ios; the iOS body stays context-free (iOS has no
  external discoverer).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants